'''
Created on 29-05-2012

@author: Magda
'''

from PyQt4 import QtGui,QtCore
import pyodbc

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s


class Ui_editProduct(QtGui.QWidget):
    productComboBox = ""
    productPrice = 0
    productQuantity = 0
    
    def getAllProducts(self):
        conn = pyodbc.connect(self.databaseDir)
        cur = conn.cursor()
        cur.execute("exec getAllProducts")
        rows = cur.fetchall()
        
        '''Dodawanie nowych itemow do comboboxa'''
        for row in rows:
            self.productComboBox.addItem(str(row[0]) + ", " + str(row[1]))
            print str(row[0])
        conn.close()
        
    '''
        wygenerowane gui
    '''
    def setupUi(self,scrollAreaWidgetContents_2,lastProductY,databaseDir,id_note,product):
        self.product = product
        self.id_note = id_note
        self.databaseDir = databaseDir
        self.scrollAreaWidgetContents_2 = scrollAreaWidgetContents_2
        horizontalLayoutWidget = QtGui.QWidget(self.scrollAreaWidgetContents_2)
        horizontalLayoutWidget.setGeometry(QtCore.QRect(9, lastProductY, 401, 31))
        newProductHorizontalLayout = QtGui.QHBoxLayout(horizontalLayoutWidget)
        newProductHorizontalLayout.setMargin(0)
        newProductHorizontalLayout.setObjectName(_fromUtf8("newProductHorizontalLayout"))
        self.productComboBox = QtGui.QComboBox(horizontalLayoutWidget)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.productComboBox.sizePolicy().hasHeightForWidth())
        self.productComboBox.setSizePolicy(sizePolicy)
        self.productComboBox.setMinimumSize(QtCore.QSize(140, 0))
        self.productComboBox.setMaximumSize(QtCore.QSize(7777, 16777215))
        self.productComboBox.setObjectName(_fromUtf8("productComboBox"))
        newProductHorizontalLayout.addWidget(self.productComboBox)
        self.getAllProducts()
               
        self.productQuantityLineEdit = QtGui.QLineEdit(horizontalLayoutWidget)
        self.productQuantityLineEdit.setObjectName(_fromUtf8("productQuantityLineEdit"))
  
  
        newProductHorizontalLayout.addWidget(self.productQuantityLineEdit)
        self.productMeasureLabel = QtGui.QLabel(horizontalLayoutWidget)
        self.productMeasureLabel.setObjectName(_fromUtf8("productMeasureLabel"))
        newProductHorizontalLayout.addWidget(self.productMeasureLabel)
        self.productPriceLineEdit = QtGui.QLineEdit(horizontalLayoutWidget)
        self.productPriceLineEdit.setObjectName(_fromUtf8("productPriceLineEdit"))
        
        newProductHorizontalLayout.addWidget(self.productPriceLineEdit)
        productPriceLabel = QtGui.QLabel(horizontalLayoutWidget)
        productPriceLabel.setObjectName(_fromUtf8("productPriceLabel"))
        newProductHorizontalLayout.addWidget(productPriceLabel)
        self.productMeasureLabel.setText(QtGui.QApplication.translate("dayWidgetNewNote", "kg", None, QtGui.QApplication.UnicodeUTF8))
        productPriceLabel.setText(QtGui.QApplication.translate("dayWidgetNewNote", "zl", None, QtGui.QApplication.UnicodeUTF8))